package com.qcby.controller;

import com.qcby.dao.UserHouseMapper;
import com.qcby.model.House;
import com.qcby.model.Sell;
import com.qcby.service.HouseService;
import com.qcby.service.SaleService;
import com.qcby.service.UserIntegralService;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: Tom
 * @Date: 2021/07/23/16:19
 * @Description:
 */
@RequestMapping("userequip")
@Controller
public class UserEquipController {

  @Autowired
  private HttpSession session;
  @Autowired
  private SaleService saleService;
  @Autowired
  private UserIntegralService userIntegralService;
  @Autowired
  private HouseService houseService;

  @RequestMapping("quchongzhi")
  public String quchongzhiao() {
    return "user-equip/chongzhi";
  }

  @RequestMapping("show")
  public String show(Model model, Integer price) {
    Integer i = Integer.parseInt(session.getAttribute("userId").toString());
    Integer currentPrice = userIntegralService.selectPrice(i);
    Integer sum = currentPrice + price;
    userIntegralService.updataByPrice(i, sum);
    model.addAttribute("success", "充值成功");
    return "user-equip/auctionhouse";
  }

  @RequestMapping("goHouse")
  public String goHouse() {
    return "user-equip/house";
  }

  @RequestMapping("house")
  public String house(Model model) {
    Integer i = Integer.parseInt(session.getAttribute("userId").toString());
    System.out.println(i);
    List<House> u = houseService.selectByUserId(i);
    model.addAttribute("u", u);
    return "user-equip/house";
  }

  @RequestMapping("goSell")
  public String goSell(Model model, Integer id, Integer state, Integer price) {
    System.out.println(price);
    houseService.updataStateById(id);
    Sell sell = houseService.selectById(id);
    sell.setPrice(price);
    saleService.insert(sell);
    return "user-equip/house";
  }
}